
INCLUDE(FindPythonInterp)

IF(PYTHONINTERP_FOUND)
  SET(PYTHON ${PYTHON_EXECUTABLE})
ELSE(PYTHONINTERP_FOUND)
  MESSAGE(FATAL_ERROR "No Python interpreter found")
ENDIF(PYTHONINTERP_FOUND)

IF(TESTNGPP_DISABLE_SANDBOX)
  ADD_DEFINITIONS(-DTESTNGPP_DISABLE_SANDBOX=1)
ELSE(TESTNGPP_DISABLE_SANDBOX)  
  ADD_DEFINITIONS(-DTESTNGPP_DISABLE_SANDBOX=0)
ENDIF(TESTNGPP_DISABLE_SANDBOX)

IF(TESTNGPP_DISABLE_RC)
  ADD_DEFINITIONS(-DTESTNGPP_DISABLE_RC=1)
ELSE(TESTNGPP_DISABLE_RC)  
  ADD_DEFINITIONS(-DTESTNGPP_DISABLE_RC=0)
ENDIF(TESTNGPP_DISABLE_RC)

IF(CMAKE_SYSTEM_NAME MATCHES Linux)
  IF(CMAKE_COMPILER_IS_GNUCXX)
    SET(CMAKE_MODULE_LINKER_FLAGS "-Wl,--fatal-warnings -Wl,--no-undefined")
  ENDIF(CMAKE_COMPILER_IS_GNUCXX)
ENDIF(CMAKE_SYSTEM_NAME MATCHES Linux)

IF(MSVC)
SET(SAMPLE_CASES 
  ${CMAKE_CURRENT_SOURCE_DIR}/TestFoo.h)
ELSE(MSVC)
SET(SAMPLE_CASES 
  ${CMAKE_CURRENT_SOURCE_DIR}/TestCxxTest.h
  ${CMAKE_CURRENT_SOURCE_DIR}/TestBar.h
  ${CMAKE_CURRENT_SOURCE_DIR}/TestMemLeak.h)
ENDIF(MSVC)

SET(SAMPLE_SRC   ${CMAKE_CURRENT_BINARY_DIR}/sample.cpp)

SET(TEST_GENERATOR ${CMAKE_SOURCE_DIR}/scripts/testngppgen.py)

IF(MSVC)
  SET(ENCODING gb2312)
ELSE(MSVC)
  SET(ENCODING utf-8)
ENDIF(MSVC)

ADD_CUSTOM_COMMAND(
  OUTPUT ${SAMPLE_SRC}
  COMMAND ${PYTHON} ${TEST_GENERATOR} -e ${ENCODING} -o ${SAMPLE_SRC} ${SAMPLE_CASES}
  DEPENDS ${SAMPLE_CASES}
)

LINK_DIRECTORIES(${CMAKE_BINARY_DIR}/src)

ADD_LIBRARY(sample MODULE ${SAMPLE_SRC})

INCLUDE_DIRECTORIES(BEFORE ${CMAKE_SOURCE_DIR}/include .)

IF(MSVC)
	INCLUDE_DIRECTORIES(BEFORE ${CMAKE_SOURCE_DIR}/3rdparty/ .)
ENDIF(MSVC)

SET_TARGET_PROPERTIES(sample PROPERTIES SUFFIX ".so")

TARGET_LINK_LIBRARIES(sample testngpp)

ADD_CUSTOM_TARGET(sample_src DEPENDS ${SAMPLE_SRC})

ADD_DEPENDENCIES(sample sample_src)

IF(MSVC)
	CONFIGURE_FILE(run-sample.bat.in ${CMAKE_CURRENT_BINARY_DIR}/run-sample.bat)
ELSE()
	CONFIGURE_FILE(run-sample.in ${CMAKE_CURRENT_BINARY_DIR}/run-sample)	
ENDIF()
